import { ref, Ref } from "vue";
import { getDictList } from "@/api/modules/system"; //引入封装数字字典接口

/**
 * 获取字典数据
 */

// 定义字典项的数据结构
interface DictItem {
  label: string;
  value: any;
}

export function getDict(...dictNames: string[]): { [key: string]: Ref<DictItem[]> } {
  const dictData: { [key: string]: Ref<DictItem[]> } = {};

  dictNames.forEach(dictName => {
    const dictRef = ref<DictItem[]>([]);
    dictData[dictName] = dictRef;

    getDictList(dictName).then(result => {
      dictRef.value = result.data.body.map(p => ({
        label: p.dictLabel,
        value: p.dictValue
      }));
    });
  });

  return dictData;
}
